#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UTable.Objects.Controls;
using UTable.Input.Keyboard;
using System.Windows.Media;

namespace UTable.Objects
{
    public class VirtualKeyboardContent: UObject, IKeyboard
    {
        public UKeyboard Keyboard { get; set; }

        public VirtualKeyboardContent(): base()
        {
            this.MenuDisplay = UObjectMenuDisplayType.Hide;
            this.ShowsActivationEffects = false;
            Keyboard = new UKeyboard();
            this.Content = Keyboard;
            Keyboard.KeyPressed += new KeyInputEventHandler(Keyboard_KeyPressed);
            Keyboard.KeyDown += new KeyInputEventHandler(Keyboard_KeyDown);
            Keyboard.KeyUp += new KeyInputEventHandler(Keyboard_KeyUp);
        }

        void Keyboard_KeyUp(KeyInputEventArgs args)
        {
            if (KeyUp != null)
                KeyUp(args);
        }

        void Keyboard_KeyDown(KeyInputEventArgs args)
        {
            if (KeyDown != null)
                KeyDown(args);
        }

        void Keyboard_KeyPressed(KeyInputEventArgs args)
        {
            if (KeyPressed != null)
                KeyPressed(args);
        }

        public ModifierKeys Modifiers
        {
            get
            {
                return Keyboard.Modifiers;
            }
        }

        public IInputNode Target
        {
            get { return Keyboard.Target; }
        }

        public IInputNode Focus(IInputNode element)
        {
            return Keyboard.Focus(element);
        }

        public KeyStates GetKeyStates(Key key)
        {
            return Keyboard.GetKeyStates(key);
        }

        public bool IsKeyDown(Key key)
        {
            return Keyboard.IsKeyDown(key);
        }

        public bool IsKeyToggled(Key key)
        {
            return Keyboard.IsKeyToggled(key);
        }

        public bool IsKeyUp(Key key)
        {
            return Keyboard.IsKeyUp(key);
        }


        public new event KeyInputEventHandler KeyDown;

        public new event KeyInputEventHandler KeyUp;

        public event KeyInputEventHandler KeyPressed;

        internal delegate KeyStates GetKeyStatesHandler(Key key);
        internal delegate bool CheckKeyStateHandler(Key key);
        internal delegate IInputNode FocusHandler(IInputNode element);

    }
}
